import {get, post, put, del, upload} from '@/utils/request';

export interface BaseResponse {
    createBy?: string
    createTime?: string
    updateBy?: string
    updateTime?: string
}
export interface SelectApiProps {
    url: string;
    method: 'get' | 'post' | 'put' | "del" | 'upload'
    data: any
}
export interface BaseListResponse<T> {
    rows: T[];
    total: number;
}

// 创建一个映射对象，将方法名映射到request的对应方法
const methodMap: any = {
    get: get,
    post: post,
    put: put,
    delete: del,
    upload: upload
};

export const getSelectOptionsApi = (options: SelectApiProps): Promise<any> => {
    const { url, method, data } = options;
    // 检查方法名是否有效
    if (!methodMap[method]) {
        throw new Error(`Unsupported method: ${method}`);
    }
    return methodMap[method](url, data);
}